home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 August (Alt) / CHIP 2005-08.1.iso / program / guvenlik / syslinux-3.07.exe / cache.inc < prev    next >
Encoding:
Text File  |  2004-12-17  |  1.8 KB  |  78 lines

  1. ; -*- fundamental -*- ---------------------------------------------------
  2. ;   
  3. ;   Copyright 2004 H. Peter Anvin - All Rights Reserved
  4. ;
  5. ;   This program is free software; you can redistribute it and/or modify
  6. ;   it under the terms of the GNU General Public License as published by
  7. ;   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
  8. ;   Boston MA 02111-1307, USA; either version 2 of the License, or
  9. ;   (at your option) any later version; incorporated herein by reference.
  10. ;
  11. ; -----------------------------------------------------------------------
  12. ; $Id: cache.inc,v 1.1 2004/12/17 10:04:50 hpa Exp $
  13.  
  14.         section .text
  15. ;
  16. ; initcache: Initialize the cache data structures
  17. ;
  18. initcache:
  19.         xor eax,eax            ; We don't care about sector 0
  20.         mov di,CachePtrs
  21.         mov cx,65536/SECTOR_SIZE
  22.         rep stosd
  23.         ret
  24.  
  25.  
  26. ;
  27. ; getcachesector: Check for a particular sector (EAX) in the sector cache,
  28. ;          and if it is already there, return a pointer in GS:SI
  29. ;          otherwise load it and return said pointer.
  30. ;
  31. ;        Assumes CS == DS.
  32. ;
  33. getcachesector:
  34.         push cx
  35.         mov si,cache_seg
  36.         mov gs,si
  37.         mov si,CachePtrs    ; Sector cache pointers
  38.         mov cx,65536/SECTOR_SIZE
  39. .search:
  40.         cmp eax,[si]
  41.         jz .hit
  42.         add si,4
  43.         loop .search
  44.  
  45. .miss:
  46.         ; Need to load it.  Highly inefficient cache replacement
  47.         ; algorithm: Least Recently Written (LRW)
  48.         push bx
  49.         push es
  50.         push gs
  51.         pop es
  52.         mov bx,[NextCacheSlot]
  53.         inc bx
  54.         and bx,(1 << (16-SECTOR_SHIFT))-1
  55.         mov [NextCacheSlot],bx
  56.         shl bx,2
  57.         mov [CachePtrs+bx],eax
  58.         shl bx,SECTOR_SHIFT-2
  59.         mov si,bx
  60.         pushad
  61.         call getonesec
  62.         popad
  63.         pop es
  64.         pop bx
  65.         pop cx
  66.         ret
  67.  
  68. .hit:        ; We have it; get the pointer
  69.         sub si,CachePtrs
  70.         shl si,SECTOR_SHIFT-2
  71.         pop cx
  72.         ret
  73.  
  74.         section .bss
  75.         alignb 4
  76. CachePtrs    resd 65536/SECTOR_SIZE    ; Cached sector pointers
  77. NextCacheSlot    resw 1            ; Next cache slot to occupy
  78.